import { ElMessageBox } from 'element-plus'
export default {
  // 登录
  setUserInfo(state, data) {
    state.userInfo = data
    console.log(data);
    sessionStorage.shopToken = JSON.stringify(data)
    // console.log(JSON.stringify(state));
  },
  //  注销
  loginOut(state) {
    state.userInfo = {}
    sessionStorage.removeItem("shopToken")
  },
  // 添加购物车
  addShopping(state, shopInfo) {
    for (var i = 0; i < state.cart.length; i++) {
      if (state.cart[i].goodsId == shopInfo.goodsId) {
        console.log();
        ElMessageBox.confirm(
          '购物车已有该商品!',
          {
            confirmButtonText: '确定加入',
            cancelButtonText: "放弃加入购物车"
          }
        ).then(() => {

          state.cart[i].number =   state.cart[i].number*1+shopInfo.number*1

          console.log("state:"+state.cart[i].number);
          console.log(shopInfo.number);
        })
        return
      }
    }
    state.cart.push(shopInfo)
  }
}